import {
  mangerstudent, // 添加学生接口
  mangerstudentedit, // 更新学生信息接口
  mangerstudentid, // 删除学生接口
  addmangerroom, // 添加教室接口
  mangerroomupdate, // 更新教室接口
  mangerroomdelete, // 删除教室接口
  mangergrade, // 添加班级接口
  mangergradeupdate, // 更新班级信息
  mangergradedelete, // 删除班级接口
  getmangergrade, // 获取已经分配教室的班级的接口
  mangerroom, // 获取全部教室
  // getmangerstudent, // 已经分班学生接口
  mangerstudentnew, // 没有分班学生接口
  // mangergradenew // 获取没有分配教室的班级
  fetchSubject // 全部课程
} from '@/services/classmanagement'
export default {

    namespace: 'classmanagemeng',
  
    state: {
      getmangergradeList:[],
      getmangergradesubjectList: [],
      fetchSubjectList: [],
      mangerroom: []
    },
  
    subscriptions: {
      setup({ dispatch, history }) {  // eslint-disable-line
        dispatch({
          type: 'getmangergrade'
        })
      },
    },
  
    effects: {
      *getmangergrade({ payload }, { call, put }) {
        const data = yield call(getmangergrade)
        yield put({
          type: 'changeState',
          payload: {
            getmangergradeList: data
          }
        })
        yield put({
          type: 'getmangergradesubject'
        })
      },
      *getmangergradesubject({ payload }, { call, put }) {
        const promiseAll = [
          getmangergrade(),
          fetchSubject(),
          mangerroom()
        ]
        const initData = () => Promise.all(promiseAll)
        const res = yield call(initData)
        yield put({
          type: 'changeState',
          payload: {
            getmangergradesubjectList: res[0].data,
            fetchSubjectList: res[1].data,
            mangerroom: res[2].data
          }
        })
      },
      *mangergrade({payload}, {call, put}){
        console.log(payload);
        const data = yield call(mangergrade, payload)
        console.log(data)
        yield put({
          type: 'getmangergrade'
        })
      },
      *mangergradedelete({ payload }, {call, put}){
        const data = yield call(mangergradedelete, { grade_id: payload})
        console.log(data)
        yield put({
          type: 'getmangergrade'
        })
      }
    },
  
    reducers: {
      changeState(state, action) {
        console.log(action,'1s...........')
        return { ...state, ...action.payload };
      },
    },
  };